package com.wowocai.btchina.utils.ip;

import java.math.BigDecimal;

public class ObjectUtil {

    public static boolean isNone(String st) {
        return st == null || st.equals("");
    }

    public static String getString(String st) {
        return st == null ? "" : st.trim();
    }

    public static int getInt(String st) {
        return st == null || (st.trim()).equals("") ? 0 : Integer.parseInt(st.trim());
    }

    public static int getInt(Object st) {
        try {
            return st == null ? 0 : Integer.parseInt(st.toString());
        } catch (Exception e) {
            return 0;
        }
    }

    public static long getLong(String st) {
        return st == null || (st.trim()).equals("") ? 0 : Long.parseLong(st.trim());
    }

    public static long getLong(Object st) {
        String st1 = getString(st);
        try {
            return st1 == null || st1.trim().length() == 0 ? 0 : Long.parseLong(st1);
        } catch (Exception e) {
            return 0;
        }
    }

    public static float getFloat(Object st) {
        return (null == st || "".equals(st)) ? 0 : Float.parseFloat(st.toString());
    }

    public static String getString(Object o) {
        return o == null ? "" : o.toString();
    }

    public static BigDecimal getBigDecimal(Object o) {
        return o == null ? null : new BigDecimal(o.toString());
    }

    /**
     * 将数据转成Boolean类型 <br/>
     * TODO(The execution flow of the method described here - Optional).<br/>
     * TODO(Note to describe the method of this method - Optional).<br/>
     * Modify records :<br/>
     * 
     * @author 刘建成
     * @param para
     * @return
     */

    public static boolean getBoolean(String para) {
        String para_ = para == null ? null : para.trim().toLowerCase();
        if (para_ == null || para_.length() == 0) {
            return false;
        }
        try {
            return Boolean.valueOf(para);
        } catch (Exception e) {
            return false;
        }
    }
}
